package com.group4.vod.controller;

import com.group4.vod.service.VideoService;
import com.study.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Set;

@Api(description="阿里云视频点播微服务")
@CrossOrigin //跨域
@RestController
@RequestMapping("/admin/vod/video")
public class VideoAdminController {

	@Autowired
	private VideoService videoService;

	@PostMapping("upload")
	@ApiOperation("上传视频")
	public ResponseResult uploadVideo(
			@ApiParam(name = "file", value = "文件", required = true)
			@RequestParam("file") MultipartFile file) throws Exception {

		String videoId = videoService.uploadVideo(file);
		return new ResponseResult<String>(200,"视频上传成功",videoId);
	}

	@DeleteMapping("{videoId}")
	public ResponseResult removeVideo(@ApiParam(name = "videoId", value = "云端视频id", required = true)
						 @PathVariable String videoId){

		videoService.removeVideo(videoId);
		return new ResponseResult<>("视频删除成功");
	}

	/**
	 * 批量删除视频
	 * @param videoIdSet
	 * @return
	 */
	@DeleteMapping("delete-batch")
	public ResponseResult<Void> removeVideoList(
			@ApiParam(name = "videoIdList", value = "云端视频id", required = true)
			@RequestParam("videoIdList") Set<String> videoIdSet){

		videoService.removeVideoList(videoIdSet);

		return ResponseResult.SUCCESS;
	}
}